//
//  WKComposeViewController.m
//  WKDemo
//
//  Created by wangzhaohui-Mac on 14-8-7.
//  Copyright (c) 2014年 com.app. All rights reserved.
//

#import "WKComposeViewController.h"
#import "WKComposeButton.h"

#define btnX 25
#define upBtnY self.view.centerY - 50
#define downBtnY upBtnY + 100
#define btnW 62
#define mgr 100
@interface WKComposeViewController ()

@end

@implementation WKComposeViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
 
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.alpha = 0.9;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //添加菜单按钮
        [self setMenuButton];
    });
    
    //设置取消按钮
    [self setupCancelButton];
    

}
/**
 *添加菜单按钮
 */
- (void)setMenuButton
{
    //按钮1
    WKComposeButton *btn1 = [WKComposeButton composeButton];
    //取消按钮高亮时的阴影显示
    btn1.adjustsImageWhenHighlighted = NO;
    btn1.frame = CGRectMake(btnX, 0, btnW, btnW);
    [btn1 setTitle:@"发图片" forState:UIControlStateNormal];
    [btn1 setBackgroundImage:[UIImage imageNamed:@"publish-picture"] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(btn1Click:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn1];
    
    //按钮2
    WKComposeButton *btn2 = [WKComposeButton composeButton];
    //取消按钮高亮时的阴影显示
    btn2.adjustsImageWhenHighlighted = NO;
    btn2.frame = CGRectMake(btnX+mgr, 0, btnW, btnW);
    [btn2 setTitle:@"发段子" forState:UIControlStateNormal];
    [btn2 setBackgroundImage:[UIImage imageNamed:@"publish-text"] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(btn1Click:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn2];
    
    //按钮3
    WKComposeButton *btn3 = [WKComposeButton composeButton];
    //取消按钮高亮时的阴影显示
    btn3.adjustsImageWhenHighlighted = NO;
    btn3.frame = CGRectMake(btnX+2*mgr, 0, btnW, btnW);
    [btn3 setTitle:@"发声音" forState:UIControlStateNormal];
    [btn3 setBackgroundImage:[UIImage imageNamed:@"publish-audio"] forState:UIControlStateNormal];
    [btn3 addTarget:self action:@selector(btn1Click:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn3];
    
    //按钮4
    WKComposeButton *btn4 = [WKComposeButton composeButton];
    //取消按钮高亮时的阴影显示
    btn4.adjustsImageWhenHighlighted = NO;
    btn4.frame = CGRectMake(btnX, 0, btnW, btnW);
    [btn4 setTitle:@"发视频" forState:UIControlStateNormal];
    [btn4 setBackgroundImage:[UIImage imageNamed:@"publish-video"] forState:UIControlStateNormal];
    [btn4 addTarget:self action:@selector(btn1Click:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn4];
    
    //按钮5
    WKComposeButton *btn5 = [WKComposeButton composeButton];
    //取消按钮高亮时的阴影显示
    btn5.adjustsImageWhenHighlighted = NO;
    btn5.frame = CGRectMake(btnX+mgr, 0, btnW, btnW);
    [btn5 setTitle:@"审贴" forState:UIControlStateNormal];
    [btn5 setBackgroundImage:[UIImage imageNamed:@"publish-review"] forState:UIControlStateNormal];
    [btn5 addTarget:self action:@selector(btn1Click:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn5];

    [UIView animateWithDuration:0.8 delay:0.0 usingSpringWithDamping:0.5
          initialSpringVelocity:25 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
              btn1.y = upBtnY;
              btn2.y = upBtnY;
              btn3.y = upBtnY;
              btn4.y = downBtnY;
              btn5.y = downBtnY;
          } completion:^(BOOL finished) {
          }];
//    
//    [UIView animateWithDuration:0.8 delay:0.0 usingSpringWithDamping:0.5
//          initialSpringVelocity:25 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
//              btn2.y = upBtnY;
//          } completion:^(BOOL finished) {
//          }];
//    
//    [UIView animateWithDuration:0.8 delay:0.0 usingSpringWithDamping:0.5
//          initialSpringVelocity:20 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
//              btn3.y = upBtnY;
//          } completion:^(BOOL finished) {
//          }];
//    
//    [UIView animateWithDuration:0.8 delay:0.0 usingSpringWithDamping:0.5
//          initialSpringVelocity:20 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
//              btn4.y = downBtnY;
//          } completion:^(BOOL finished) {
//          }];
//    
//    [UIView animateWithDuration:0.8 delay:0.0 usingSpringWithDamping:0.5
//          initialSpringVelocity:25 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
//              btn5.y = downBtnY;
//          } completion:^(BOOL finished) {
//          }];
}

/**
 *  设置取消按钮
 */
- (void)setupCancelButton
{
    //创建按钮
    UIButton *btn = [[UIButton alloc] init];
    //取消按钮高亮时的阴影显示
    btn.adjustsImageWhenHighlighted = NO;
    [btn setTitle:@"取消" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"msgTitleCellBackground"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(cancelButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    CGFloat buttonX = 10;
    CGFloat buttonH = 40;
    CGFloat buttonY = self.view.height - buttonH - buttonX;
    CGFloat buttonW = 300;
    btn.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH);
    [self.view addSubview:btn];
}

- (void)btn1Click:(UIButton *)button
{
    
    WKLog(@"btn1Click===%@",button.titleLabel.text);
}


/**
 *  移除控制器
 */
- (void)cancelButtonClick:(UIButton *)btn
{
    [self dismissViewControllerAnimated:NO completion:^{
    }];
    
}


@end
